import {Component, OnInit} from '@angular/core';
import {ApisService} from '../../apis.service';
import {ActivatedRoute, Router} from '@angular/router';

@Component({selector: 'app-search', templateUrl: './search.component.html', styleUrls: ['./search.component.css']})
export class SearchComponent implements OnInit {
  currentPage:number=1;
  numPages:number=0;
  curPageNum:number=1;
  query : string = "";
  constructor(private router : Router,private route : ActivatedRoute) {}

  ngOnInit() {
    this
      .route
      .params
      .subscribe(x => {
        this.route.queryParams.subscribe(p=>{
          this.query = x.query;
          this.currentPage = p.pn||1;
          this.curPageNum=parseInt(p.pn);
        });
      });
  }
  pageChanged(ev){
    this
      .router
      .navigate( ['search',this.query],{queryParams:{pn:ev.page}});
  }
}
